package com.kma.summer2012.client.view.breadCrumbs;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.*;
import com.kma.summer2012.client.SiteMap;
import com.kma.summer2012.client.presenters.breadcrumbs.BreadCrumbsPresenter;
import com.kma.summer2012.client.styles.style2.Recources;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: EUGENE
 * Date: 3/6/13
 * Time: 2:50 AM
 * To change this template use File | Settings | File Templates.
 */
public class BreadCrumbs extends Composite implements BreadCrumbsPresenter.Display {
    @UiField
    protected HorizontalPanel container;

    interface BreadCrumbsUiBinder extends UiBinder<HTMLPanel, BreadCrumbs> {
    }

    private static BreadCrumbsUiBinder ourUiBinder = GWT.create(BreadCrumbsUiBinder.class);


    public BreadCrumbs() {
        HTMLPanel rootElement = ourUiBinder.createAndBindUi(this);
        this.initWidget(rootElement);
    }

    public void setPath(List<SiteMap.Node> list) {
        this.container.clear();
        if (list != null)
            for (SiteMap.Node node : list) {
                Hyperlink link = new Hyperlink(node.label, node.historyItem);
                Label sign = new Label(">");
                sign.setStyleName(Recources.INSTANCE.styles().breadCrumbsLink());
                this.container.add(sign);
                this.container.add(link);
            }
    }

    @Override
    public Widget asWidget() {
        return this;
    }

}